package com.atqh.logistics.config;


import com.atqh.logistics.handler.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
    //    注入拦截器
    @Autowired
    private LoginInterceptor loginInterceptor;

    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        //跨域配置
        registry.addMapping("/**").allowedOrigins("http://localhost:8080");
    }*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("*")
                .excludePathPatterns("/custom/customlogin")
                .excludePathPatterns("/custom/register")
                .excludePathPatterns("/driver/driverlogin")
                .excludePathPatterns("/manager/managerlogin")
//                .addPathPatterns("/custom/*")
//                .addPathPatterns("/articles/view/{id}")
//                .addPathPatterns("/article/{id}")
//                .addPathPatterns("/articles/publish")
//                .addPathPatterns("/comments/article/{id}")
//                .addPathPatterns("/comments/create/change")
        ;
    }
}
